<?php
/*
 * EmailComponent for CakePHP
 *
 * @author      gwoo <gwoo@rd11.com>
 * @version     0.10.8.2176
 * @license		OPPL
 *
 */
class SearchComponent extends Object
{

	function calulate($sql,$params){

		$rnt = '';
		
		$params = $this->removeMagicQuotes($params);
		
		while (list ($hash_key, $hash_val) = each($params)) {
			if(is_array($hash_val)){
				$hash_val = "'" . implode("','",$hash_val) . "'";
			}
			if(!empty($hash_val)){
				$sql = str_replace("###".$hash_key."###", $hash_val, $sql);
			}
		}
		
		$sql_array = split('AND',$sql);

		$rnt_array = array();
		foreach( $sql_array as $sql_key => $sql_value){
			if(stripos($sql_value, '###') == 0){
				$rnt_array[] = $sql_value;
			}
		}
		
		$rnt = implode('AND',$rnt_array);
		return $rnt;
	
	}


	
	function removeMagicQuotes ($postArray, $trim = true)
	{
       $newArray = array();    
       
       foreach ($postArray as $key => $val)
       {
           if (is_array($val))
           {
               $newArray[$key] = $this->removeMagicQuotes ($val, $trim);
           }
           else
           {
               if ($trim == true)
               {
                   $val = trim($val);
               }
               $newArray[$key] = addslashes($val);
           }
       }    
       
       return $newArray;    
	} 

}

?>